import unittest
import nellypkg/[atoms, types]

suite "weak typing":

  test "auto-conversion":
    check atoms["Œu"](42.jelly) == "42".jelly
    check atoms["Œu"](6.28.jelly) == "6.28".jelly

  test "auto-vectorization":
    check atoms["Ḥ"](@[42.jelly, 6.28.jelly].jelly) == @[84.jelly, 12.56.jelly].jelly
    check atoms["Œu"](@["Foo", "bar", "baZ"].jelly) == @["FOO", "BAR", "BAZ"].jelly

suite "one-character monads":

  test "A":
    check atoms["A"](42.jelly) == 42.jelly
    check atoms["A"]((-42).jelly) == 42.jelly
    check atoms["A"](6.28.jelly) == 6.28.jelly
    check atoms["A"]((-6.28).jelly) == 6.28.jelly
    check atoms["A"](0.jelly) == 0.jelly
    check atoms["A"](0.0.jelly) == 0.0.jelly

  test "B":
    check atoms["B"](42.jelly) == @[1, 0, 1, 0, 1, 0].jelly
    check atoms["B"]((-42).jelly) == @[-1, 0, -1, 0, -1, 0].jelly
    check atoms["B"](6.28.jelly) == @[1.0, 1.0, 0.28].jelly
    check atoms["B"]((-6.28).jelly) == @[-1.0, -1.0, -0.28].jelly
    check atoms["B"](0.jelly) == @[0].jelly
    check atoms["B"](0.0.jelly) == @[0.0].jelly

  test "C":
    check atoms["C"](42.jelly) == (-41).jelly
    check atoms["C"]((-42).jelly) == 43.jelly
    check atoms["C"](6.28.jelly) == (-5.28).jelly
    check atoms["C"]((-6.28).jelly) == 7.28.jelly
    check atoms["C"](0.jelly) == 1.jelly
    check atoms["C"](0.0.jelly) == 1.0.jelly

  test "D":
    check atoms["D"](4243.jelly) == @[4, 2, 4, 3].jelly
    check atoms["D"]((-4243).jelly) == @[-4, -2, -4, -3].jelly
    check atoms["D"](216.28.jelly) == @[2.0, 1.0, 6.28].jelly
    check atoms["D"]((-216.28).jelly) == @[-2.0, -1.0, -6.28].jelly
    check atoms["D"](0.jelly) == @[0].jelly
    check atoms["D"](0.0.jelly) == @[0.0].jelly

  test "N":
    check atoms["N"](42.jelly) == (-42).jelly
    check atoms["N"]((-42).jelly) == 42.jelly
    check atoms["N"](6.28.jelly) == (-6.28).jelly
    check atoms["N"]((-6.28).jelly) == 6.28.jelly
    check atoms["N"](0.jelly) == 0.jelly
    check atoms["N"](0.0.jelly) == 0.0.jelly

  test "°":
    check atoms["°"](42.jelly) == 0.7330382858376184.jelly
    check atoms["°"]((-42).jelly) == (-0.7330382858376184).jelly
    check atoms["°"](6.28.jelly) == 0.1096066770252439.jelly
    check atoms["°"]((-6.28).jelly) == (-0.1096066770252439).jelly
    check atoms["°"](0.jelly) == 0.0.jelly
    check atoms["°"](0.0.jelly) == 0.0.jelly

  test "¹":
    check atoms["¹"](42.jelly) == 42.jelly
    check atoms["¹"]("foo".jelly) == "foo".jelly
    check atoms["¹"](@[42, 43].jelly) == @[42, 43].jelly

  test "²":
    check atoms["²"](42.jelly) == 1764.jelly
    check atoms["²"]((-42).jelly) == 1764.jelly
    check atoms["²"](6.28.jelly) == 39.4384.jelly
    check atoms["²"]((-6.28).jelly) == 39.4384.jelly
    check atoms["²"](0.jelly) == 0.jelly
    check atoms["²"](0.0.jelly) == 0.0.jelly

  test "W":
    check atoms["W"](42.jelly) == @[42].jelly
    check atoms["W"]("foo".jelly) == @["foo"].jelly
    check atoms["W"](@[42, 43].jelly) == @[@[42, 43]].jelly

  test "Ḥ":
    check atoms["Ḥ"](42.jelly) == 84.jelly
    check atoms["Ḥ"]((-42).jelly) == (-84).jelly
    check atoms["Ḥ"](6.28.jelly) == 12.56.jelly
    check atoms["Ḥ"]((-6.28).jelly) == (-12.56).jelly

suite "misc nilads":

  test "ØB":
    check atoms["ØB"]() == @[0, 1].jelly

suite "misc monads":

  test "Œu":
    check atoms["Œu"]("Hello world!".jelly) == "HELLO WORLD!".jelly
